using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using Gios.Pdf;

namespace ACEMPortal.ACEM.Forms.Reports
{
	/// <summary>
	/// Summary description for PDFReport.
	/// </summary>
	public class PDFReport
	{
		public PDFReport()
		{
			//
			// TODO: Add constructor logic here
			//
		}

		public static PdfDocument MakePDF(ref ACEMDataManager.AnomaliesData.Anomalies anomaliesCollection, bool bNotUserReport)
		{
			PdfDocument myPdfDocument=new PdfDocument(PdfDocumentFormat.A4_Horizontal);
			//PdfDocument myPdfDocument=new PdfDocument(PdfDocumentFormat.InCentimeters(21,29.7));
			
			System.Data.DataTable dt = anomaliesCollection.GetDataTable(bNotUserReport);

			PdfTable myPdfTable=myPdfDocument.NewTable(new Font("Verdana",12),dt.Rows.Count,dt.Columns.Count,4);
			myPdfTable.ImportDataTable(dt );

			// Sets the format for correct date-time representation
			

			// Now we set our Graphic Design: Colors and Borders...
			myPdfTable.HeadersRow.SetColors(Color.White,Color.Navy);
			myPdfTable.SetColors(Color.Black,Color.White,Color.Gainsboro);
			myPdfTable.SetBorders(Color.Black,1,BorderType.CompleteGrid);

			// With just one method we can set the proportional width of the columns.
			// It's a "percentage like" assignment, but the sum can be different from 100.

			if (bNotUserReport) 
			{
				myPdfTable.SetColumnsWidth(new int[]{20,15,20,20,20,20,10,30});
				myPdfTable.Columns[1].SetContentFormat("{0:dd/MM/yyyy}");
			}
			else
			{
				myPdfTable.SetColumnsWidth(new int[]{15,20,20,20,20,10,30});
				myPdfTable.Columns[0].SetContentFormat("{0:dd/MM/yyyy}");
			}

			// You can also set colors for a range of cells, in this case, a row:
			//myPdfTable.Rows[7].SetColors(Color.Black,Color.LightGreen);
					
			// Now we set some alignment... for the whole table and then, for a column.
			myPdfTable.SetContentAlignment(ContentAlignment.MiddleCenter);
			myPdfTable.Columns[1].SetContentAlignment(ContentAlignment.MiddleLeft);

			PdfImage LogoImage=myPdfDocument.NewImage("c:\\inetpub\\wwwroot\\SFPortal\\images\\SF.jpg");

			/*double x = 0;
			double y = 20;
			double delta = 20;
			double deltax=700;
			PdfArea area1 = new PdfArea (myPdfDocument,x, y, x + deltax, y+delta);
			PdfArea area2 = new PdfArea (myPdfDocument,x, y+delta, x + deltax, y+(2*delta));
			PdfArea area3 = new PdfArea (myPdfDocument,x, y+(2*delta), x + deltax, y+(3*delta));
			PdfArea area4 = new PdfArea (myPdfDocument,x, y+(3*delta), x + deltax, y+(4*delta));

			PdfTextArea pta1=new PdfTextArea(new Font("Verdana",12,FontStyle.Bold),Color.Red
				,area1,ContentAlignment.MiddleCenter,"Gruppo Millepiani");

			PdfTextArea pta2=new PdfTextArea(new Font("Verdana",12,FontStyle.Bold),Color.Red
				,area2,ContentAlignment.MiddleCenter,"Corso Europa 76 - 20020 Solaro (MI)");

			PdfTextArea pta3=new PdfTextArea(new Font("Verdana",12,FontStyle.Bold),Color.Red
				,area3,ContentAlignment.MiddleCenter,"Tel. +39 0292274716 - Fax +39 0292274704");

			PdfTextArea pta4=new PdfTextArea(new Font("Verdana",12,FontStyle.Bold),Color.Red
				,area4,ContentAlignment.MiddleCenter,"http://interattivo.gruppomillepiani.it");

			*/
			/*
			<a href="http://interattivo.gruppomillepiani.it">http://interattivo.gruppomillepiani.it</a>
			*/

			string sTestoAzienda = ScenarioFramework.WAPI.DataTypes.GetValue ("Anomalia","TestoAzienda");
			PdfTextArea pta=new PdfTextArea(new Font("Verdana",12,FontStyle.Bold),Color.Black
				,new PdfArea(myPdfDocument,130,30,720,120),ContentAlignment.TopLeft,sTestoAzienda);

			
			string sCaption = "Elenco Anomalie aggiornato al " + System.DateTime.Now.ToShortDateString();

			PdfTextArea pta2=new PdfTextArea(new Font("Verdana",26,FontStyle.Bold),Color.Red
				,new PdfArea(myPdfDocument,130,40,720,120),ContentAlignment.MiddleCenter,sCaption);
					
			// Here we start the loop to generate the table...
			while (!myPdfTable.AllTablePagesCreated)
			{
				// we create a new page to put the generation of the new TablePage:
				PdfPage newPdfPage=myPdfDocument.NewPage();
				
				/*PdfTablePage newPdfTablePage=
					myPdfTable.CreateTablePage(new PdfArea(myPdfDocument,48,120,500,670));
					*/
				PdfTablePage newPdfTablePage=
					myPdfTable.CreateTablePage(new PdfArea(myPdfDocument,30,120,740, 480));
									
				newPdfPage.Add(LogoImage,30,20,300);
				newPdfPage.Add(newPdfTablePage);
				newPdfPage.Add(pta);
				newPdfPage.Add(pta2);
				//newPdfPage.Add(pta3);
				//newPdfPage.Add(pta4);
						
				// Now we create a loop for serching for people born in 1968. If we find
				// one, we will draw a circle over the number. This is possible using the
				// the CellArea, that is the Area occupied by a rasterized Cell.
				/*for (int index=newPdfTablePage.FirstRow;index<=newPdfTablePage.LastRow;index++)
				{
					if (((DateTime)myPdfTable.Rows[index][2].Content).Year==1968)
					{
						PdfCircle pc=newPdfTablePage.CellArea(index,2).InnerCircle(Color.Blue,2);
						pc.StrokeWidth=3.5;
						newPdfPage.Add(pc);
					}
				}
				*/
				// we save each generated page before start rendering the next.
				newPdfPage.SaveToDocument();			
			}
			// Finally we save the docuement...
			//myPdfDocument.SaveToFile("c:\\inetpub\\wwwroot\\MillepianiPortal\\Example1.pdf");
			return myPdfDocument;

		}

		public static PdfDocument MakePDF(ref System.Data.DataTable dt, ref ACEMDataManager.AnomaliesData.Anomaly anomaly)
		{
			PdfDocument myPdfDocument=new PdfDocument(PdfDocumentFormat.A4);
			//System.Data.DataTable dt = anomaly.GetDataTable();

			PdfTable myPdfTable=myPdfDocument.NewTable(new Font("Verdana",12),dt.Rows.Count,dt.Columns.Count,4);
			myPdfTable.ImportDataTable(dt);

			myPdfTable.HeadersRow.SetColors(Color.White,Color.Navy);
			myPdfTable.SetColors(Color.Black,Color.White,Color.Gainsboro);
			myPdfTable.SetBorders(Color.Black,1,BorderType.CompleteGrid);

			myPdfTable.SetColumnsWidth(new int[]{20,80});

			myPdfTable.SetContentAlignment(ContentAlignment.MiddleCenter);
			myPdfTable.Columns[1].SetContentAlignment(ContentAlignment.MiddleLeft);

			PdfImage LogoImage=myPdfDocument.NewImage("c:\\inetpub\\wwwroot\\SFPortal\\images\\sf.jpg");

			string sTestoAzienda = ScenarioFramework.WAPI.DataTypes.GetValue ("Anomalia","TestoAzienda");
			PdfTextArea pta=new PdfTextArea(new Font("Verdana",12,FontStyle.Bold),Color.Black
				,new PdfArea(myPdfDocument,130,30,470,120),ContentAlignment.TopLeft,sTestoAzienda);

			
			string sCaption = anomaly.IdDocumento;

			PdfTextArea pta2=new PdfTextArea(new Font("Verdana",26,FontStyle.Bold),Color.Red
				,new PdfArea(myPdfDocument,130,40,480,120),ContentAlignment.MiddleCenter,sCaption);
					
			// Here we start the loop to generate the table...
			while (!myPdfTable.AllTablePagesCreated)
			{
				// we create a new page to put the generation of the new TablePage:
				PdfPage newPdfPage=myPdfDocument.NewPage();
				
				/*PdfTablePage newPdfTablePage=
					myPdfTable.CreateTablePage(new PdfArea(myPdfDocument,48,120,500,670));
					*/
				PdfTablePage newPdfTablePage=
					myPdfTable.CreateTablePage(new PdfArea(myPdfDocument,30,120,480, 720));
									
				newPdfPage.Add(LogoImage,30,20,300);
				newPdfPage.Add(newPdfTablePage);
				newPdfPage.Add(pta);
				newPdfPage.Add(pta2);
				newPdfPage.SaveToDocument();			
			}
			// Finally we save the docuement...
			//myPdfDocument.SaveToFile("c:\\inetpub\\wwwroot\\MillepianiPortal\\Example1.pdf");
			return myPdfDocument;

		}
	}
}
